package net.minecraft.src;

import org.lwjgl.opengl.GL11;

public class LF_TileEntityTVRenderer extends TileEntitySpecialRenderer
{
	public LF_TileEntityTVRenderer(Class class1, Class class2)
	{
		try {
			aModel = (LF_Model)(class1.newInstance());
			bModel = (LF_ModelTVScreen)(class2.newInstance());
		}
		catch(Exception e) {
			System.err.println(e);
		}
	}

	public void renderAModelAt(TileEntity tileentity1, double d, double d1, double d2, float f)
	{
		int m = ((LF_TileEntityTV)(tileentity1)).frame;
		byte c = ((LF_TileEntityTV)(tileentity1)).channel;
		int x = tileentity1.getBlockMetadata() % 4;

		GL11.glPushMatrix();
		GL11.glTranslatef((float)d + 0.5F, (float)d1 + 1.5F, (float)d2 + 0.5F);
		if(x == 0)
			GL11.glRotatef((-1*90f), 0, 1f, 0);
		if(x == 1)
			GL11.glRotatef(( 1*90f), 0, 1f, 0);
		if(x == 2)
			GL11.glRotatef(( 1*180f), 0, 1f, 0);
		if(x == 3)
			GL11.glRotatef(( 0*180F), 0, 1f, 0);
		GL11.glRotatef(180, 1f, 0, 0);
		bindTextureByName("/LordFlower/TileEntityTextures/LF_TVCase.png");

		GL11.glPushMatrix();
		aModel.renderModel(0.0625F);
		GL11.glPopMatrix();	
		GL11.glPopMatrix();

		mod_LF_GenericFurnitureMain mod = (mod_LF_GenericFurnitureMain)ModLoaderMp.getModInstance(mod_LF_GenericFurnitureMain.class);

		int cx = -1;
		int cy = -1;

		for(int frame = (m - 1) * 12; frame > 0; frame -= 12)
		{
			cx += 12;
			if((cx + 11) > mod.getChannelImageSize(c))
			{
				cx = -1;
				cy += 11;
			}
		}

		bModel = new LF_ModelTVScreen(cx, cy, mod.getChannelImageSize(c));

		GL11.glPushMatrix();
		GL11.glTranslatef((float)d + 0.5F, (float)d1 + 1.5F, (float)d2 + 0.5F);
		if(x == 0)
			GL11.glRotatef((-1*90f), 0, 1f, 0);
		if(x == 1)
			GL11.glRotatef((1*90f), 0, 1f, 0);
		if(x == 2)
			GL11.glRotatef((1*180f), 0, 1f, 0);
		if(x == 3)
			GL11.glRotatef((0*180F), 0, 1f, 0);
		GL11.glRotatef(180, 1f, 0, 0);

		if(m == 0)
			bindTextureByName("/LordFlower/TileEntityTextures/TV Screens/LF_TV0.png");
		else
			bindTextureByName("/LordFlower/TileEntityTextures/TV Screens/Channel" + c + ".png");

		GL11.glPushMatrix();
		bModel.renderModel(0.0625F);
		GL11.glPopMatrix();	
		GL11.glPopMatrix();	
	}

	public void renderTileEntityAt(TileEntity tileentity, double d, double d1, double d2, float f)
	{
		renderAModelAt((TileEntity)tileentity, d, d1, d2, f);
	}

	private LF_Model aModel;
	private LF_Model bModel;
}
